﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace WenSkin.Controls
{
    [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.All), DefaultEvent("ValueChanged")]
    public class ToolStripDateTimePicker : ToolStripControlHost
    {
        private readonly DateTimePicker mDateTimePicker;

        [Category("Wen"), Description("日期格式选择")]
        public DateTimePickerFormat Format { get => mDateTimePicker.Format; set => mDateTimePicker.Format = value; }
        [Category("Wen"), Description("自定义格式样式")]
        public string CustomFormat { get => mDateTimePicker.CustomFormat; set => mDateTimePicker.CustomFormat = value; }
        [Category("Wen"), Description("获取时间值")]
        public DateTime Value { get => mDateTimePicker.Value; set => mDateTimePicker.Value = value; }
        public ToolStripDateTimePicker() : base(new DateTimePicker())
        {
            mDateTimePicker = DateTimePicker;
            mDateTimePicker.ValueChanged += MDateTimePicker_ValueChanged;
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public DateTimePicker DateTimePicker
        {
            get { return (DateTimePicker)Control; }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override string Text
        {
            get { return string.Empty; }
            set { base.Text = string.Empty; }
        }

        public event EventHandler ValueChanged;

        private void MDateTimePicker_ValueChanged(object sender, EventArgs e)
        {
            ValueChanged?.Invoke(sender, e);
        }
    }
}
